package com.estate.business.impl;

import java.util.List;

import com.estate.business.TenderCompanyService;
import com.estate.dao.TenderCompanyDao;
import com.estate.vo.Vo;
import com.estate.vo.impl.TenderCompanyVo;
import com.estate.vo.impl.TenderVo;

public class TenderCompanyServiceImpl implements TenderCompanyService {

	private TenderCompanyDao tenderCompanyDao;

	public TenderCompanyDao getTenderCompanyDao() {
		return tenderCompanyDao;
	}

	public void setTenderCompanyDao(TenderCompanyDao tenderCompanyDao) {
		this.tenderCompanyDao = tenderCompanyDao;
	}
	
	public boolean addTenderCompany(TenderCompanyVo tenderCompany) {
		boolean result =false; 
		result = this.getTenderCompanyDao().addVo(tenderCompany);
		return result;
	}

	public List<Vo> getList(){
		List<Vo> allList = this.getTenderCompanyDao().findAll();
		
		return allList;
	}

	public TenderCompanyVo getTenderCompany(int id) {
		TenderCompanyVo project = (TenderCompanyVo) this.getTenderCompanyDao().findByPK(id);
		return project;
	}

	public boolean updateTenderCompany(TenderCompanyVo tenderCompany){
		boolean result =false;
		TenderCompanyVo old = this.getTenderCompany(tenderCompany.getId());
		tenderCompany.setPostDate(old.getPostDate());
		tenderCompany.setPostUser(old.getPostUser());
		tenderCompany.setTender(old.getTender());
		result = this.getTenderCompanyDao().updateVo(tenderCompany);
		
		return true;
	}
	
	public boolean deleteMultiTenderCompany(String delStr){
		if(delStr!= null && !"".equals(delStr) && !",".equals(delStr)){
			String[] delArray = delStr.split(",");
			TenderCompanyVo tenderCompany = null;
			for(int i = 0;i<delArray.length;i++){
				tenderCompany = new TenderCompanyVo();
				tenderCompany.setId(Integer.parseInt(delArray[i]));
				this.deleteTenderCompany(tenderCompany);
			}
		}
		return true;
	}
	
	public boolean deleteTenderCompany(TenderCompanyVo tenderCompany){
		boolean result = false;
		result = this.getTenderCompanyDao().deleteVo(tenderCompany);
		return result;
	}

	public List<TenderCompanyVo> getTenderCompanyList(TenderVo tender) {
		List<TenderCompanyVo> allList = this.getTenderCompanyDao().getTenderCompanyList(tender);
		return allList;
	}
}
